package com.otaku.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * 标题：WebSocketConfig<br>
 * 功能说明：异步通信，实现浏览器(B)与服务端(S)之间的通信<br>
 * 系统版本：v1.0<br>
 * 开发人员： ganxiang20970 <br>
 * 开发时间：2018年04月17日 17:32<br>
 */
@Configuration
@EnableWebSocketMessageBroker
//AbstractWebSocketMessageBrokerConfigurer 已被废弃，原因是Java8新特性，接口可以包含默认(default)方法，可以直接使用 WebSocketMessageBrokerConfigurer
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    //注册stomp节点以及匹配的url
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/endpointWisely")
                .withSockJS();
    }

    //配置消息代理，暂不理解
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/topic");
    }
}
